Conversation
setbap
requested changes
Dec 23, 2023
Owner
setbap
left a comment
There was a problem hiding this comment.
Thank you for your attention and time. I believe this code serves educational purposes, and it would be beneficial to include comments. I understand that for production-grade code, this may slightly reduce code readability. so i prefer to don't remove this comments.
|
|
||
| pub const MAX_PASTE_VALUE_SIZE: u32 = 16 * 1024; | ||
| pub const DELETE_TEPMLATE: &str = "DELETE"; | ||
| pub const DELETE_TEMPLATE: &str = "DELETE"; |
Comment on lines
+55
to
+93
| impl PasteData { | ||
| pub fn create(id: u64, user_id: Option<Principal>, info: PasteDataCreator) -> Self { | ||
| PasteData { | ||
| id: id.to_string(), | ||
| name: info.name, | ||
| creator: user_id, | ||
| description: info.description, | ||
| expire_date: info.expire_date, | ||
| content: info.content, | ||
| tags: _create_tags(info.tags), | ||
| version: 1, | ||
| } | ||
| } | ||
|
|
||
| pub fn update(&mut self, info: PasteDataUpdater) { | ||
| if let Some(name) = info.name { | ||
| self.name = name; | ||
| } | ||
| if let Some(desc) = info.description { | ||
| self.description = desc; | ||
| } | ||
| if let Some(content) = info.content { | ||
| self.content = content; | ||
| } | ||
| if let Some(tags) = info.tags { | ||
| self.tags = _create_tags(tags); | ||
| } | ||
|
|
||
| // Increase the number of changes | ||
| self.version += 1; | ||
| } | ||
|
|
||
| // Clear the content of the paste | ||
| pub fn clear(&mut self) { | ||
| self.name = DELETE_TEMPLATE.to_string(); | ||
| self.content = DELETE_TEMPLATE.to_string(); | ||
| self.tags = Vec::new(); | ||
| } | ||
| } |
Owner
There was a problem hiding this comment.
i don't understand what is your changes. is it git diff problem?
Comment on lines
+108
to
+111
| .split_whitespace() | ||
| .filter(|v| !v.is_empty()) | ||
| .map(String::from) | ||
| .collect() |
Owner
There was a problem hiding this comment.
this is much nice and cleaner. thanks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello @setbap
This pull request addresses various improvements and fixes in two canisters, namely
libandpaste. The changes aim to enhance code clarity, error handling, and overall maintainability.Changes in
pasteCanisterRefactored PasteData Logic: Restructured the logic for managing PasteData, improving code structure and modularity.
Improved Error Messages: Enhanced error messages for paste-related queries and updates, providing clearer information about the encountered issues.
Simplified Code for Finding Pastes: Simplified the code for finding pastes by tags, extension, name, and short URL, making it more readable and maintainable.
Optimized Paste Retrieval: Optimized the retrieval of pastes by user, last N pastes, and other queries for better performance.
General Improvements
Consistent Naming Conventions: Ensured consistent naming conventions throughout the codebase for better code readability.
Enhanced Code Comments: Improved code comments to provide better documentation and understanding of the code.
Fixed Minor Typos: Corrected minor typos in comments and variable names.